package com.liu.concurrent.sync;

public class NotifyDemo implements Runnable {

	private Object lock;

	public NotifyDemo(Object lock) {
		this.lock = lock;
	}

	public void run() {
		synchronized (lock) {
			System.out.println(Thread.currentThread().getName() + "线程开始");
			lock.notify();
			System.out.println(Thread.currentThread().getName() + "线程开始结束");
		}
	}

	public static void main(String[] args) {
		Object o = new Object();
		NotifyDemo syncTest1 = new NotifyDemo(o);
		NotifyDemo syncTest2 = new NotifyDemo(o);
		Thread thread1 = new Thread(syncTest1, "thread1");
		Thread thread2 = new Thread(syncTest2, "thread2");
		thread1.start();
		thread2.start();
	}
}